package bTree.LeetCode;

import java.util.ArrayList;

public class 二叉搜索树中第K小的元素 {
    ArrayList<Integer>arrayList=new ArrayList<>();
    public int kthSmallest(TreeNode root, int k) {
        dfs(root);
        return arrayList.get(k-1);
    }

    private void dfs(TreeNode Node) {
        if(Node==null){
            return;
        }
        dfs(Node.left);
        arrayList.add(Node.val);
        dfs(Node.right);
    }
}